package com.beans;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/4/4 18:34
 */
@Controller
public class ControllerDemo {
    //Could not autowire. There is more than one bean of 'User' type.
//    方式一： 属性注入     实际开发最多使用
    @Autowired
    @Qualifier(value = "user1")
    //或者
//    @Resource(name = "user1")
    private User user;
//    方式二：构造方法注入    当下spring推荐
//    private UserController controller;
//    @Autowired
//    public ControllerDemo (UserController userController){
//            controller = userController;
//    }
//    方式三：setter注入     早期spring官方推荐
//    private UserController controller;
//    @Autowired
//    public void setController(UserController controller) {
//        this.controller = controller;
//    }

    public void sayHello(){
        System.out.println(user);
    }
}
